Skip to content

Extract rule: template-self-closing-void-elements#2617

Merged
NullVoxPopuli merged 2 commits intoember-cli:masterfrom
NullVoxPopuli:nvp/template-lint-extract-rule-template-self-closing-void-elements
Mar 19, 2026
Merged

Extract rule: template-self-closing-void-elements#2617
NullVoxPopuli merged 2 commits intoember-cli:masterfrom
NullVoxPopuli:nvp/template-lint-extract-rule-template-self-closing-void-elements

Conversation

@NullVoxPopuli
Copy link
Copy Markdown
Contributor

Split from #2371.

Copy link
Copy Markdown

@NullVoxPopuli-ai-agent NullVoxPopuli-ai-agent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: template-self-closing-void-elements (PR #2617)

Comparison with ember-template-lint source

General correctness:

  1. Fix implementation is incomplete: The rule declares fixable: 'code' in meta, but the create() function never provides a fix function in context.report(). This means ESLint will advertise the rule as fixable, but --fix will not actually change anything. The tests use output: null confirming no fix is applied. Either remove fixable: 'code' from meta, or implement the fixer. The original ETL rule does implement fixing (using ember-template-recast builders and this.mode === 'fix').

  2. Detection mechanism differs: The original ETL checks this.sourceForNode(node).trim() and looks at the last two characters (/> or not). The ESLint version uses node.selfClosing property. This is cleaner and should be reliable if the Glimmer ESLint parser correctly sets selfClosing on element nodes. Worth verifying that the parser's selfClosing matches the source text behavior.

  3. Void element list: Both versions use the same set of 16 void elements. The ESLint version uses a Set (better lookup performance), the original uses a plain object. Functionally equivalent.

  4. Schema: The ESLint version uses oneOf: [{ type: 'boolean' }, { type: 'string', enum: ['require'] }]. The original ETL accepts true (enable default), false (disable), or 'require'. In the ESLint version, passing true or false would be handled — true is truthy but not === 'require', so it falls into the "disallow self-closing" default behavior. false similarly falls into default. This differs from the original where false disables the rule entirely. Bug: When options[0] is false, the ESLint version still runs and reports self-closing elements as redundant. It should return early/disable when false is passed.

  5. Default behavior when no config: When no option is passed, config is undefined, and requireSelfClosing is false, so the rule defaults to disallowing self-closing. This matches the original ETL's default behavior (config true → disallow self-closing).

Scope analysis (gjs/gts):

Not applicable. This rule checks HTML void element tags and self-closing syntax — purely structural, no name matching involved.

Tests: Good coverage of all 16 void elements in both modes, including the 'require' config variant. The complex void element test with attributes, modifiers, comments, and block params is a nice addition.

Summary: Two issues to address: (1) fixable: 'code' is declared but no fixer is implemented — either implement it or remove the declaration; (2) false config should disable the rule rather than running with default behavior.

🤖 Automated review comparing with ember-template-lint source

@NullVoxPopuli NullVoxPopuli force-pushed the nvp/template-lint-extract-rule-template-self-closing-void-elements branch from 2f60fb2 to af0a016 Compare March 19, 2026 20:24
@NullVoxPopuli NullVoxPopuli merged commit 40f4c0b into ember-cli:master Mar 19, 2026
9 checks passed
@NullVoxPopuli NullVoxPopuli deleted the nvp/template-lint-extract-rule-template-self-closing-void-elements branch March 19, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants